package com.heima.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yunfei
 * @date 2022年10月13日 14:50
 */
@Configuration
@EnableConfigurationProperties(ESProperties.class)
public class ESClient {

    @Autowired
    private ESProperties properties;

    @Bean
    public RestHighLevelClient getEsClient() {
        return new RestHighLevelClient(RestClient.builder(HttpHost.create(properties.getHost() + ":" + properties.getPort())));
    }
}
